//package me.firstapp.service.weixin.kami.impl;
//
//import java.math.BigDecimal;
//import java.math.RoundingMode;
//import java.util.Date;
//import java.util.List;
//import java.util.Map;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import me.firstapp.common.exception.ServiceException;
//import me.firstapp.common.exception.StatusHouse;
//import me.firstapp.common.utils.DateUtils;
//import me.firstapp.common.utils.MD5Utils;
//import me.firstapp.common.utils.Page;
//import me.firstapp.common.utils.StrUtils;
//import me.firstapp.module.weixin.jinbi.JinBiAccount;
//import me.firstapp.module.weixin.jinbi.JinBiAccountTrace;
//import me.firstapp.module.weixin.kami.KaMi;
//import me.firstapp.module.weixin.kami.KaMiProduct;
//import me.firstapp.module.weixin.member.Member;
//import me.firstapp.module.weixin.member.PaymentRecord;
//import me.firstapp.module.weixin.order.KaMiOrder;
//import me.firstapp.module.weixin.order.MobileFareOrder;
//import me.firstapp.module.weixin.system.ThisSystem;
//import me.firstapp.module.weixin.weibi.WeiBiAccount;
//import me.firstapp.module.weixin.weibi.WeiBiAccountTrace;
//import me.firstapp.module.weixin.weibi.WeiBiAccountTrace.ChangeType;
//import me.firstapp.repository.weixin.JinBiAccountRepository;
//import me.firstapp.repository.weixin.JinBiAccountTraceRepository;
//import me.firstapp.repository.weixin.KaMiOrderRepository;
//import me.firstapp.repository.weixin.KaMiProductRepository;
//import me.firstapp.repository.weixin.KaMiRepository;
//import me.firstapp.repository.weixin.MemberRepository;
//import me.firstapp.repository.weixin.PaymentRecordRepository;
//import me.firstapp.repository.weixin.ThisSystemRepository;
//import me.firstapp.repository.weixin.WeiBiAccountRepository;
//import me.firstapp.repository.weixin.WeiBiAccountTraceRepository;
//import me.firstapp.service.weixin.kami.KaMiOrderService;
//
//@Service
//public class KaMiOrderServiceImpl implements KaMiOrderService {
//
//	private static Logger logger = LoggerFactory.getLogger(KaMiOrderServiceImpl.class);
//
//	@Autowired
//	private KaMiOrderRepository kaMiOrderRepository;
//
//	@Autowired
//	private MemberRepository memberRepository;
//
//	@Autowired
//	private KaMiRepository kaMiRepository;
//
//	@Autowired
//	private KaMiProductRepository kaMiProductRepository;
//
//	@Autowired
//	private WeiBiAccountRepository weiBiAccountRepository;
//
//	@Autowired
//	private WeiBiAccountTraceRepository weiBiAccountTraceRepository;
//
//	@Autowired
//	private JinBiAccountRepository jinBiAccountRepository;
//
//	@Autowired
//	private JinBiAccountTraceRepository jinBiAccountTraceRepository;
//
//	@Autowired
//	private PaymentRecordRepository paymentRecordRepository;
//
//	@Autowired
//	private ThisSystemRepository thisSystemRepository;
//
//	@Override
//	public Page<KaMiOrder> findKaMiOrderPageByOpenId(Integer pageNo, Integer pageSize, String openId) {
//		return kaMiOrderRepository.findKaMiOrderPageByOpenId(pageNo, pageSize, openId);
//	}
//
//	@Override
//	public KaMiOrder executeCreateKaMiOrder(String openId, Long kaMiProductId, String remark) {
//		Member member = memberRepository.findMemberByOpenId(openId);
//		if (null == member) {
//			throw new ServiceException(StatusHouse.STATUS_MEMBER_NOT_EXIST);
//		}
//		KaMiProduct kaMiProduct = (KaMiProduct) kaMiProductRepository.getById(kaMiProductId);
//		if (null == kaMiProduct) {
//			throw new ServiceException(StatusHouse.STATUS_PRODUCT_NOT_EXIST);
//		}
//		if (KaMiProduct.STATUS_OFF == kaMiProduct.getStatus()) {
//			throw new ServiceException(StatusHouse.STATUS_PRODUCT_OFF_ERROR);
//		}
//		KaMiOrder kaMiOrder = new KaMiOrder();
//		if (KaMiProduct.SEND_TYPE_SYSTEM.equals(kaMiProduct.getSendType())) {
//			List<KaMi> kamiList = kaMiRepository.findKaMiList(kaMiProduct.getId(), KaMi.STATUS_NO_SALE);
//			if (kamiList.isEmpty()) {
//				throw new ServiceException(StatusHouse.STATUS_STOCK_NOT_ENOUGH);
//			}
//			KaMi kaMi = kamiList.get(0);
//			if (KaMi.GIVE_TYPE_CAN_NOT == kaMi.getGiveType()) {
//				kaMi.setStatus(KaMi.STATUS_ORDER_LOCK);
//				kaMiRepository.update(kaMi);
//			}
//			kaMiOrder.setKaMiId(kaMi.getId());
//		}
//		ThisSystem thisSystem = thisSystemRepository.findThisSystem();
//		member.setFlow(member.getFlow() + 1);
//		memberRepository.update(member);
//		String orderNoStart = KaMiOrder.ORDER_NO_START + DateUtils.getNowStr("yyMMdd") + member.getId();
//		String orderNoEnd = String.valueOf(member.getFlow());
//		int lenth = thisSystem.getOrderNoLength() - orderNoStart.length() - orderNoEnd.length();
//		StringBuffer sb = new StringBuffer("");
//		for (int i = 0; i < lenth; i++) {
//			sb.append(String.valueOf(StrUtils.getRandomInt()));
//		}
//		kaMiOrder.setOrderNo(orderNoStart + sb.toString() + orderNoEnd);
//		kaMiOrder.setOpenId(openId);
//		kaMiOrder.setCardNo(member.getCardNo());
//		kaMiOrder.setChiefOpenId(member.getChiefOpenId());
//		kaMiOrder.setChiefCardNo(member.getChiefCardNo());
//		kaMiOrder.setKaMiProductId(kaMiProductId);
//		kaMiOrder.setName(kaMiProduct.getName());
//		kaMiOrder.setPayPoint(kaMiProduct.getExchangePoint());
//		kaMiOrder.setChannel(kaMiProduct.getChannel());
//		if (Member.VIP_LEVEL_FANS == member.getVipLevel()) {
//			kaMiOrder.setAmount(kaMiProduct.getFansPrice());
//			kaMiOrder.setPayAmount(kaMiProduct.getFansPrice());
//			if (KaMiProduct.CHANNEL_SALE.equals(kaMiProduct.getChannel())) {
//				kaMiOrder.setGivePoint(kaMiProduct.getFansPrice());
//			} else if (KaMiProduct.CHANNEL_EXCHANGE.equals(kaMiProduct.getChannel())) {
//				kaMiOrder.setGivePoint(BigDecimal.ZERO);
//			} else {
//				kaMiOrder.setGivePoint(BigDecimal.ZERO);
//			}
//
//		} else if (Member.VIP_LEVEL_BASE == member.getVipLevel()) {
//			kaMiOrder.setAmount(kaMiProduct.getBaseVipPrice());
//			kaMiOrder.setPayAmount(kaMiProduct.getBaseVipPrice());
//			if (KaMiProduct.CHANNEL_SALE.equals(kaMiProduct.getChannel())) {
//				kaMiOrder.setGivePoint(kaMiProduct.getBaseVipPrice());
//			} else if (KaMiProduct.CHANNEL_EXCHANGE.equals(kaMiProduct.getChannel())) {
//				kaMiOrder.setGivePoint(BigDecimal.ZERO);
//			} else {
//				kaMiOrder.setGivePoint(BigDecimal.ZERO);
//			}
//		} else if (Member.VIP_LEVEL_HIGHT == member.getVipLevel()) {
//			kaMiOrder.setAmount(kaMiProduct.getHighVipPrice());
//			kaMiOrder.setPayAmount(kaMiProduct.getHighVipPrice());
//			if (KaMiProduct.CHANNEL_SALE.equals(kaMiProduct.getChannel())) {
//				kaMiOrder.setGivePoint(kaMiProduct.getHighVipPrice());
//			} else if (KaMiProduct.CHANNEL_EXCHANGE.equals(kaMiProduct.getChannel())) {
//				kaMiOrder.setGivePoint(BigDecimal.ZERO);
//			} else {
//				kaMiOrder.setGivePoint(BigDecimal.ZERO);
//			}
//		}
//		kaMiOrder.setChiefBaseVipJinBi(kaMiProduct.getChiefBaseVipJinBi());
//		kaMiOrder.setChiefHighVipJinBi(kaMiProduct.getChiefHighVipJinBi());
//		kaMiOrder.setChiefBaseVipPoint(kaMiProduct.getChiefBaseVipPoint());
//		kaMiOrder.setChiefHighVipPoint(kaMiProduct.getChiefHighVipPoint());
//		kaMiOrder.setStatus(KaMiOrder.STATUS_NOT_PAY);
//		kaMiOrder.setSendType(kaMiProduct.getSendType());
//		kaMiOrder.setCreateTime(new Date());
//		kaMiOrder.setRemark(remark);
//		kaMiOrder.setSettleFlag(KaMiOrder.SETTLE_FLAG_NOT);
//		kaMiOrderRepository.save(kaMiOrder);
//		return kaMiOrder;
//	}
//
//	@Override
//	public KaMiOrder findKaMiOrder(String openId, String orderNo) {
//		return kaMiOrderRepository.findKaMiOrder(openId, orderNo);
//	}
//
//	@Override
//	public KaMi findKaMiByOrderNo(String openId, String orderNo) {
//		KaMiOrder order = kaMiOrderRepository.findKaMiOrderByOrderNo(orderNo);
//		if (null == order) {
//			throw new ServiceException(StatusHouse.STATUS_ORDER_NOT_EXIST);
//		}
//		if (!order.getOpenId().equals(openId)) {
//			throw new ServiceException(StatusHouse.STATUS_ORDER_ERROR);
//		}
//		Long kaMiId = order.getKaMiId();
//		KaMi kaMi = (KaMi) kaMiRepository.getById(kaMiId);
//		if (null == kaMi) {
//			throw new ServiceException(StatusHouse.STATUS_PRODUCT_NOT_EXIST);
//		}
//		if (KaMi.GIVE_TYPE_CAN_NOT == kaMi.getGiveType()) {
//			if (KaMi.STATUS_SALED != kaMi.getStatus()) {
//				throw new ServiceException(StatusHouse.STATUS_ORDER_STATUS_ERROR);
//			}
//		}
//		return kaMi;
//	}
//
//	@Override
//	public Long findTotalOrderCounts(String chiefOpenId) {
//		return kaMiOrderRepository.findTotalOrderCounts(chiefOpenId);
//	}
//
//	@Override
//	public Page<KaMiOrder> findKaMiOrderPageByChiefOpenId(Integer pageNo, Integer pageSize, String chiefOpenId) {
//		return kaMiOrderRepository.findKaMiOrderPageByChiefOpenId(pageNo, pageSize, chiefOpenId);
//	}
//
//	@Override
//	public Long findOrdersCounts(Integer status, Integer giveFareStatus) {
//		return kaMiOrderRepository.findOrdersCounts(status, giveFareStatus);
//	}
//
//	@Override
//	public List<KaMiOrder> findOrders(Integer status) {
//		return kaMiOrderRepository.findOrders(status);
//	}
//
//	@Override
//	public Page<KaMiOrder> findKaMiOrderPage(Integer pageNo, Integer pageSize, Map<String, Object> searchParams,
//			String sortParam, String sortType, Date startTime, Date endTime) {
//		return kaMiOrderRepository.findKaMiOrderPage(pageNo, pageSize, searchParams, sortParam, sortType, startTime,
//				endTime);
//	}
//
//	@Override
//	public KaMiOrder executeUpdate(KaMiOrder kaMiOrder) {
//		kaMiOrderRepository.update(kaMiOrder);
//		return kaMiOrder;
//	}
//
//	@Override
//	public KaMiOrder executeCancelOrder(KaMiOrder kaMiOrder) {
//		kaMiOrder.setStatus(KaMiOrder.STATUS_CANCEL);
//		kaMiOrder.setCancelTime(new Date());
//		kaMiOrderRepository.update(kaMiOrder);
//		if (null != kaMiOrder.getKaMiId()) {
//			KaMi kaMi = (KaMi) kaMiRepository.getById(kaMiOrder.getKaMiId());
//			if (null != kaMi) {
//				kaMi.setStatus(KaMi.STATUS_NO_SALE);
//				kaMiRepository.update(kaMi);
//			}
//		}
//		return kaMiOrder;
//	}
//
//	@Override
//	public KaMiOrder executeSettle(KaMiOrder kaMiOrder) {
//		if (KaMiOrder.SETTLE_FLAG_YES == kaMiOrder.getSettleFlag()) {
//			return kaMiOrder;
//		}
//		Member member = memberRepository.findMemberByOpenId(kaMiOrder.getOpenId());
//
//		// ==========模块一：购物者积分结算 start=============
//		WeiBiAccount memberWeiBiAccount = weiBiAccountRepository.findWeiBiAccountByCardNoAndOpenId(member.getCardNo(),
//				member.getOpenId());
//		if (!MD5Utils.verify(memberWeiBiAccount.getBalance().doubleValue() * 10000 + "",
//				memberWeiBiAccount.getEncryption())) {
//			logger.info("用户【" + member.getCardNo() + "】积分账户金额异常!");
//		} else {
//			if (kaMiOrder.getGivePoint().doubleValue() <= 0.00009999) {
//				logger.info("订单【" + kaMiOrder.getOrderNo() + "】待赠送购买者积分为0!");
//			} else {
//				WeiBiAccountTrace memberWeiBiAccountTrace = new WeiBiAccountTrace();
//				memberWeiBiAccountTrace.setWeiBiAccountId(memberWeiBiAccount.getId());
//				memberWeiBiAccountTrace.setChangeType(ChangeType.SELF_CONSUME_ADD);
//				memberWeiBiAccountTrace.setBeforeValue(memberWeiBiAccount.getBalance());
//				memberWeiBiAccountTrace.setChangeValue(kaMiOrder.getGivePoint());
//				BigDecimal memberWeiBiAfterValue = memberWeiBiAccount.getBalance().add(kaMiOrder.getGivePoint())
//						.setScale(4, RoundingMode.HALF_UP);
//				memberWeiBiAccountTrace.setAfterValue(memberWeiBiAfterValue);
//				memberWeiBiAccountTrace.setChangeTime(new Date());
//				memberWeiBiAccountTrace.setChangeDate(Integer.valueOf(DateUtils.getDateStr(new Date(), "yyyyMMdd")));
//				weiBiAccountTraceRepository.save(memberWeiBiAccountTrace);
//
//				memberWeiBiAccount.setBalance(memberWeiBiAfterValue);
//				memberWeiBiAccount.setEncryption(MD5Utils.generate(memberWeiBiAfterValue.doubleValue() * 10000 + ""));
//				memberWeiBiAccount.setUpdateTime(new Date());
//				weiBiAccountRepository.update(memberWeiBiAccount);
//			}
//		}
//		// ==========购物者积分结算 end=============
//
//		// ==================模块二：上级结算 start=======================
//		Member chiefMember = memberRepository.findMemberByOpenId(kaMiOrder.getChiefOpenId());
//		if (null == chiefMember) {
//			// 更新订单结算标志
//			kaMiOrder.setSettleFlag(MobileFareOrder.SETTLE_FLAG_YES);
//			kaMiOrder.setSettleTime(new Date());
//			kaMiOrderRepository.update(kaMiOrder);
//			logger.info("卡密订单【" + kaMiOrder.getOrderNo() + "】已结算完成。");
//			return kaMiOrder;
//		}
//		if (chiefMember.getVipLevel() == Member.VIP_LEVEL_FANS) {
//			logger.info("用户【" + member.getCardNo() + "】的上级【" + chiefMember.getCardNo() + "】的等级为粉丝，无需结算");
//		} else {
//			// ==========上级积分结算 start=============
//			WeiBiAccount chiefWeiBiAccount = weiBiAccountRepository
//					.findWeiBiAccountByCardNoAndOpenId(chiefMember.getCardNo(), chiefMember.getOpenId());
//			if (!MD5Utils.verify(chiefWeiBiAccount.getBalance().doubleValue() * 10000 + "",
//					chiefWeiBiAccount.getEncryption())) {
//				logger.info("用户【" + member.getCardNo() + "】的上级【" + chiefMember.getCardNo() + "】的积分账户金额异常!");
//			} else {
//				BigDecimal chiefMemberWeiBiChangeValue = BigDecimal.ZERO;
//				if (chiefMember.getVipLevel() == Member.VIP_LEVEL_BASE) {
//					chiefMemberWeiBiChangeValue = kaMiOrder.getChiefBaseVipPoint();
//				} else if (chiefMember.getVipLevel() == Member.VIP_LEVEL_HIGHT) {
//					chiefMemberWeiBiChangeValue = kaMiOrder.getChiefHighVipPoint();
//				}
//				if (chiefMemberWeiBiChangeValue.doubleValue() <= 0.000099) {
//					logger.info("订单【" + kaMiOrder.getOrderNo() + "】待赠送购买者上级的积分为0!");
//				} else {
//					WeiBiAccountTrace chiefMemberWeiBiAccountTrace = new WeiBiAccountTrace();
//					chiefMemberWeiBiAccountTrace.setWeiBiAccountId(chiefWeiBiAccount.getId());
//					chiefMemberWeiBiAccountTrace.setChangeType(ChangeType.FANS_CONSUME_ADD);
//					chiefMemberWeiBiAccountTrace.setBeforeValue(chiefWeiBiAccount.getBalance());
//					chiefMemberWeiBiAccountTrace.setChangeValue(chiefMemberWeiBiChangeValue);
//					BigDecimal chiefMemberWeiBiAfterValue = chiefWeiBiAccount.getBalance()
//							.add(chiefMemberWeiBiChangeValue).setScale(4, RoundingMode.HALF_UP);
//					chiefMemberWeiBiAccountTrace.setAfterValue(chiefMemberWeiBiAfterValue);
//					chiefMemberWeiBiAccountTrace.setChangeTime(new Date());
//					chiefMemberWeiBiAccountTrace
//							.setChangeDate(Integer.valueOf(DateUtils.getDateStr(new Date(), "yyyyMMdd")));
//					weiBiAccountTraceRepository.save(chiefMemberWeiBiAccountTrace);
//
//					chiefWeiBiAccount.setBalance(chiefMemberWeiBiAfterValue);
//					chiefWeiBiAccount
//							.setEncryption(MD5Utils.generate(chiefMemberWeiBiAfterValue.doubleValue() * 10000 + ""));
//					chiefWeiBiAccount.setUpdateTime(new Date());
//					weiBiAccountRepository.update(chiefWeiBiAccount);
//				}
//
//			}
//			// ==========上级积分结算 end=============
//
//			// ==========上级贝币结算 start=============
//			JinBiAccount chiefMemberJinBiAccount = jinBiAccountRepository
//					.findJinBiAccountByCardNoAndOpenId(chiefMember.getCardNo(), chiefMember.getOpenId());
//			if (!MD5Utils.verify(chiefMemberJinBiAccount.getBalance().doubleValue() * 10000 + "",
//					chiefMemberJinBiAccount.getEncryption())) {
//				logger.info("用户【" + member.getCardNo() + "】的上级【" + chiefMember.getCardNo() + "】的贝币账户金额异常!");
//			} else {
//				BigDecimal chiefMemberJinBiChangeValue = BigDecimal.ZERO;
//				if (chiefMember.getVipLevel() == Member.VIP_LEVEL_BASE) {
//					chiefMemberJinBiChangeValue = kaMiOrder.getChiefBaseVipJinBi();
//				} else if (chiefMember.getVipLevel() == Member.VIP_LEVEL_HIGHT) {
//					chiefMemberJinBiChangeValue = kaMiOrder.getChiefHighVipJinBi();
//				}
//				if (chiefMemberJinBiChangeValue.doubleValue() <= 0.000099) {
//					logger.info("订单【" + kaMiOrder.getOrderNo() + "】待赠送购买者上级的贝币为0!");
//				} else {
//					JinBiAccountTrace chiefMemberinBiAccountTrace = new JinBiAccountTrace();
//					chiefMemberinBiAccountTrace.setJinBiAccountId(chiefMemberJinBiAccount.getId());
//					chiefMemberinBiAccountTrace.setChangeType(
//							me.firstapp.module.weixin.jinbi.JinBiAccountTrace.ChangeType.FANS_CONSUME_ADD);
//					chiefMemberinBiAccountTrace.setBeforeValue(chiefMemberJinBiAccount.getBalance());
//					chiefMemberinBiAccountTrace.setChangeValue(chiefMemberJinBiChangeValue);
//					BigDecimal chiefMemberJinBiAfterValue = chiefMemberJinBiAccount.getBalance()
//							.add(chiefMemberJinBiChangeValue).setScale(4, RoundingMode.HALF_UP);
//					chiefMemberinBiAccountTrace.setAfterValue(chiefMemberJinBiAfterValue);
//					chiefMemberinBiAccountTrace.setChangeTime(new Date());
//					chiefMemberinBiAccountTrace
//							.setChangeDate(Integer.valueOf(DateUtils.getDateStr(new Date(), "yyyyMMdd")));
//					jinBiAccountTraceRepository.save(chiefMemberinBiAccountTrace);
//
//					chiefMemberJinBiAccount.setBalance(chiefMemberJinBiAfterValue);
//					chiefMemberJinBiAccount
//							.setEncryption(MD5Utils.generate(chiefMemberJinBiAfterValue.doubleValue() * 10000 + ""));
//					chiefMemberJinBiAccount.setUpdateTime(new Date());
//					jinBiAccountRepository.update(chiefMemberJinBiAccount);
//				}
//			}
//			// ==========上级贝币结算 end===============
//		}
//		// ==================上级结算 end=======================
//
//		// ===========模块三：上级的上级如果是代理级别，则可吃下级代理的返利[返利计算：支付金额x2%x50%]==============
//		Member chiefChiefMember = memberRepository.findMemberByOpenId(chiefMember.getChiefOpenId());
//		if (null == chiefChiefMember) {
//			// 更新订单结算标志
//			kaMiOrder.setSettleFlag(MobileFareOrder.SETTLE_FLAG_YES);
//			kaMiOrder.setSettleTime(new Date());
//			kaMiOrderRepository.update(kaMiOrder);
//			logger.info("卡密订单【" + kaMiOrder.getOrderNo() + "】已结算完成。");
//			return kaMiOrder;
//		}
//
//		if ((Member.VIP_LEVEL_HIGHT == chiefChiefMember.getVipLevel())
//				&& (Member.VIP_LEVEL_HIGHT == chiefMember.getVipLevel())) {
//			BigDecimal changeJinBiValue = kaMiOrder.getPayAmount().multiply(new BigDecimal(0.02))
//					.multiply(new BigDecimal(0.5)).setScale(4, RoundingMode.HALF_UP);
//			if (changeJinBiValue.doubleValue() > 0.000099999) {
//				JinBiAccount jinBiAccount = jinBiAccountRepository
//						.findJinBiAccountByCardNoAndOpenId(chiefChiefMember.getCardNo(), chiefChiefMember.getOpenId());
//				if (MD5Utils.verify(jinBiAccount.getBalance().doubleValue() * 10000 + "",
//						jinBiAccount.getEncryption())) {
//					JinBiAccountTrace jinBiAccountTrace = new JinBiAccountTrace();
//					jinBiAccountTrace.setJinBiAccountId(jinBiAccount.getId());
//					jinBiAccountTrace.setChangeType(
//							me.firstapp.module.weixin.jinbi.JinBiAccountTrace.ChangeType.JINBI_ADD_DAILI);
//					jinBiAccountTrace.setBeforeValue(jinBiAccount.getBalance());
//					jinBiAccountTrace.setChangeValue(changeJinBiValue);
//					BigDecimal afterValue = jinBiAccount.getBalance().add(changeJinBiValue).setScale(4,
//							RoundingMode.HALF_UP);
//					jinBiAccountTrace.setAfterValue(afterValue);
//					jinBiAccountTrace.setChangeTime(new Date());
//					jinBiAccountTrace.setChangeDate(Integer.valueOf(DateUtils.getDateStr(new Date(), "yyyyMMdd")));
//					jinBiAccountTraceRepository.save(jinBiAccountTrace);
//
//					jinBiAccount.setBalance(afterValue);
//					jinBiAccount.setEncryption(MD5Utils.generate(afterValue.doubleValue() * 10000 + ""));
//					jinBiAccount.setUpdateTime(new Date());
//					jinBiAccountRepository.update(jinBiAccount);
//				} else {
//					logger.info("用户【" + member.getCardNo() + "】的上级【" + chiefMember.getCardNo() + "】的上级【"
//							+ chiefChiefMember.getCardNo() + "】的贝币账户金额异常!");
//				}
//			}
//		}
//		// 更新订单结算标志
//		kaMiOrder.setSettleFlag(MobileFareOrder.SETTLE_FLAG_YES);
//		kaMiOrder.setSettleTime(new Date());
//		kaMiOrderRepository.update(kaMiOrder);
//		logger.info("卡密订单【" + kaMiOrder.getOrderNo() + "】已结算完成。");
//		return kaMiOrder;
//	}
//
//	@Override
//	public List<KaMiOrder> findOrders(Integer status, Integer settleFlag) {
//		return kaMiOrderRepository.findOrders(status, settleFlag);
//	}
//
//	@Override
//	public void executeConfirmOrder(KaMiOrder kaMiOrder) {
//		if (null == kaMiOrder) {
//			return;
//		}
//		kaMiOrder.setStatus(KaMiOrder.STATUS_PAYED);
//		kaMiOrder.setAccountDate(new Date());
//		kaMiOrderRepository.update(kaMiOrder);
//	}
//
//	@Override
//	public void executeSavePaymentRecord(KaMiOrder kaMiOrder, String thirdPayNo, Integer status, String errorCode,
//			String errorDesc) {
//		if (kaMiOrder == null) {
//			return;
//		}
//		PaymentRecord paymentRecord = new PaymentRecord();
//		paymentRecord.setOrderNo(kaMiOrder.getOrderNo());
//		paymentRecord.setOpenId(kaMiOrder.getOpenId());
//		paymentRecord.setCardNo(kaMiOrder.getCardNo());
//		paymentRecord.setThirdPayNo(thirdPayNo);
//		paymentRecord.setPayAmount(kaMiOrder.getPayAmount());
//		paymentRecord.setStatus(status);
//		paymentRecord.setPayTime(new Date());
//		paymentRecord.setErrorCode(errorCode);
//		paymentRecord.setErrorDesc(errorDesc);
//		paymentRecordRepository.save(paymentRecord);
//	}
//
//	@Override
//	public void executeCompleteSysOrder(KaMiOrder kaMiOrder) {
////		KaMiProduct kaMiProduct = null;
////		try {
////			if (KaMiOrder.STATUS_PAYED != kaMiOrder.getStatus()) {
////				return;
////			}
////			if (!KaMiProduct.SEND_TYPE_SYSTEM.equals(kaMiOrder.getSendType())) {
////				return;
////			}
////			KaMi kaMi = (KaMi) kaMiRepository.getById(kaMiOrder.getKaMiId());
////			kaMiProduct = (KaMiProduct) kaMiProductRepository.getById(kaMiOrder.getKaMiProductId());
////			StringBuilder text = new StringBuilder(
////					"尊敬的用户，您购买的【" + kaMiOrder.getName() + "】付款成功，订单编号【" + kaMiOrder.getOrderNo() + "】\n\n");
////			text.append("账号：" + kaMi.getAccount() + "\n");
////			text.append("秘钥：" + kaMi.getKey() + "\n\n");
////			text.append("使用说明：" + kaMiProduct.getRemark());
////
////			String openId = kaMiOrder.getOpenId();
////			WeixinProxy weixinProxy = new WeixinProxy();
////			NotifyApi notifyApi = new NotifyApi(weixinProxy.getTokenManager());
////			notifyApi.sendNotify(new NotifyMessage(openId, new Text(text.toString())));
////
////			if (KaMi.GIVE_TYPE_CAN_NOT == kaMi.getGiveType()) {
////				kaMi.setStatus(KaMi.STATUS_SALED);
////				kaMiRepository.update(kaMi);
////			}
////			kaMiOrder.setStatus(KaMiOrder.STATUS_COMPLETE);
////			kaMiOrder.setCompleteTime(new Date());
////			kaMiOrderRepository.update(kaMiOrder);
////		} catch (WeixinException e1) {
////			e1.printStackTrace();
////			logger.error("卡密订单【" + kaMiOrder.getOrderNo() + "】发送卡密失败,改为手动发送！", e1);
////			if (null != kaMiProduct) {
////				kaMiProduct.setSendType(KaMiProduct.SEND_TYPE_HAND);
////				kaMiProductRepository.update(kaMiProduct);
////			}
////		} catch (Exception e) {
////			e.printStackTrace();
////			logger.error("卡密订单【" + kaMiOrder.getOrderNo() + "】发送卡密失败！", e);
////			throw new ServiceException("error", "卡密订单【" + kaMiOrder.getOrderNo() + "】发送卡密失败");
////		}
//	}
//
//	@Override
//	public void executeCompleteHandOrder(KaMiOrder kaMiOrder) {
//		kaMiOrder.setStatus(KaMiOrder.STATUS_COMPLETE);
//		kaMiOrder.setCompleteTime(new Date());
//		kaMiOrderRepository.update(kaMiOrder);
//		// 调用微信通知，通知用户订单完成
//		try {
//
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//	}
//
//}
